package com.handler

import com.Config
import com.UploadQueue.Companion.create
import com.amazonaws.services.s3.model.DeleteObjectsRequest
import com.amazonaws.services.s3.transfer.MyTransferManager

class PackHandler(transferManager: MyTransferManager?) : BaseHandler<Any>(transferManager) {
    override fun execute() {
        println("执行删除操作")

        val packCmd = Config.dataManage!!.packCmd

        if (packCmd.deleteFileList != null && packCmd.deleteFileList!!.isNotEmpty()) {
            println("删除数量 len=" + packCmd.deleteFileList!!.size)
            val deleteObjectsResult = DeleteObjectsRequest(packCmd.bucketName)
                .withKeys(packCmd.deleteFileList)
            s3Client?.deleteObjects(deleteObjectsResult)
        }

        println("全部删除完成！")

        println("执行上传操作")

        create()
            .setTransferManager(transferManager)
            .startUpload(packCmd.uploadFileList)

        println("全部上传完成！")

        // 关闭client
        transferManager?.shutdownNow()
    }
}
